package com.sgb.zhaocai.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;
import com.sgb.zhaocai.base.BaseApi;
import com.sgb.zhaocai.entity.AddInviteExternalListBean;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import java.util.HashMap;
import java.util.Map;

/**
 * 邀请报名详情页    再次邀请
 */
public class PickInvitedApplyDetailsModel extends AndroidViewModel {

    public MutableLiveData<Boolean> dialog = new MutableLiveData<>();
    public ObservableField<Integer> page = new ObservableField<>(1);
    public MutableLiveData<String> showToast = new MutableLiveData<>();
    private Map map;

    public PickInvitedApplyDetailsModel(@NonNull Application application) {
        super(application);
    }

    //添加招标邀请信息
    public void addBiddingInvite(String[] companyNo, String inviteConditions, String tenderNo, String fromWhere, String[] userNo,String type) {
        dialog.setValue(true);
        map = new HashMap();
        map.put("companyNo", companyNo);
        map.put("inviteConditions", inviteConditions);   //邀请报价条件
        if ("1".equals(fromWhere)) {
            map.put("tenderNo", tenderNo);
        } else if ("2".equals(fromWhere)) {
            map.put("bidNo", tenderNo);
        }
        map.put("type", type);
        map.put("userNo", userNo);

        BaseApi.getApi().addBiddingInvite(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                dialog.setValue(false);
                showToast.setValue("邀请成功");
            }
        });
    }

    //招标再次邀请
    public void inviteBiddingAgain(String id) {
        dialog.setValue(true);

        BaseApi.getApi().inviteBiddingAgain(id).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                dialog.setValue(false);
                showToast.setValue("邀请成功");
            }
        });
    }

    //添加竞价邀请信息
    public void addBidInvite(String companyNo[], String inviteConditions, String tenderNo, String fromWhere, String[] userNo, String type) {
        dialog.setValue(true);
        map = new HashMap();
        map.put("companyNo", companyNo);
        map.put("inviteConditions", inviteConditions);
        if ("1".equals(fromWhere)) {
            map.put("tenderNo", tenderNo);
        } else if ("2".equals(fromWhere)) {
            map.put("bidNo", tenderNo);
        }
        map.put("type", type);
        map.put("userNo", userNo);

        BaseApi.getApi().addBidInvite(map).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                dialog.setValue(false);
                showToast.setValue("邀请成功");
            }
        });
    }

    //再次邀请竞价
    public void inviteBidAgain(String id) {
        dialog.setValue(true);

        BaseApi.getApi().inviteBidAgain(id).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                dialog.setValue(false);
                showToast.setValue("邀请成功");
            }
        });
    }

    /**
     * 邀请非网站客户
     * @param bean
     */
    public void saveZcInviteTenderExternal(AddInviteExternalListBean bean) {
        BaseApi.getApi().getSaveZcInviteTenderExternal(bean).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                dialog.setValue(false);
                showToast.setValue("邀请成功");
            }
        });
    }

    /**
     * 竞价非网站客户
     * @param bean
     */
    public void saveZcInviteBidExternal(AddInviteExternalListBean bean) {
        BaseApi.getApi().getsaveZcInviteBidExternal(bean).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                dialog.setValue(false);
                showToast.setValue("邀请成功");
            }
        });
    }
}
